package com.gxa.web_admin.controller.accesscontroller;

import com.gxa.common.R;
import com.gxa.modules.pojo.AlarmRules;
import com.gxa.modules.pojo.AlarmType;
import com.gxa.modules.pojo.PushMode;
import com.gxa.modules.pojo.Role;
import com.gxa.modules.service.accessservice.ResourceService;
import com.gxa.modules.service.accessservice.impl.ResourceServiceImpl;
import io.swagger.annotations.*;
import com.gxa.modules.pojo.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.util.ArrayList;

/**
 * 资源管理
 */
@RestController
@RequestMapping(value = "resource ")
@Api(value = "资源管理模块",tags = "资源管理API")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;


    /**
     * 查询所有资源信息
     * @return 返回所有资源信息
     */
    @RequestMapping(value = "selectResource",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有资源信息接口",notes = "根据传入信息查询所有资源信息",httpMethod = "GET", response = String.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resourceName",value = "资源名称",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "resourceLevel",value = "资源等级",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "page",value = "当前页码",paramType = "query",dataType = "String",required = true),
            @ApiImplicitParam(name = "size",value = "每页显示条数",paramType = "query",dataType = "String",required = true)
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectResource(String resourceName, String resourceLevel,String page,String size){
        return resourceService.selectResource(resourceName,  resourceLevel,page,size);
    }


    /**
     * 新增资源
     * @return 返回成功
     */
    @RequestMapping(value = "insertResource",method = RequestMethod.POST)
    @ApiOperation(value = "新增资源接口",notes = "新增资源",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertResource(@RequestBody @ApiParam(name = "insertResourceJson",
            value = "资源名称、资源等级、接口地址、创建时间",required = true)
                                       Resource resource){


        return resourceService.insertResource(resource);
    }


    /**
     * 删除资源
     * @return 返回删除成功
     */
    @RequestMapping(value = "deleteResource",method = RequestMethod.POST)
    @ApiOperation(value = "删除资源接口",notes = "根据传入id删除资源",httpMethod = "POST", response = String.class)
    @ApiImplicitParam(name = "resourceId",value = "资源id",paramType = "query",dataType = "String",required = true)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R deleteResource(String resourceId){
        return resourceService.deleteResource(resourceId);
    }

    /**
     * 修改资源
     * @return 返回成功
     */
    @RequestMapping(value = "updateResource",method = RequestMethod.POST)
    @ApiOperation(value = "修改资源接口",notes = "修改资源",httpMethod = "POST", response = String.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateResource(@RequestBody @ApiParam(name = "updateResourceJson",
            value = "告警规则id、资源名称、资源等级、接口地址、修改时间",required = true)
                                       Resource resource){

        return resourceService.updateResource(resource);
    }
}
